<?php
error_reporting (E_ALL ^ E_NOTICE);
require("page.php");
require('addDatabaseInformation.php');
session_start();
// Get the start time
$endtime = microtime();
$endarray = explode(" ", $endtime);
$endtime = $endarray[1] + $endarray[0];
// End get start time 



// Add everything up front
$page = new Page();
$page->setHeader("Captcha Evalutaion");
$page->setFooter();
echo $page->getHeader();

try{
  $NUM_CAPTCHAS_PAGES = 5;
  // Check that we have the name
  

    
  if(!(isset($_SESSION['username']))){
    $_SESSION['username'] = $_POST['id'];
  }

  // Keeps track of the number of pages
  if(!isset($_SESSION['numcaptchas'])){
    session_register('numcaptchas');
    $_SESSION['numcaptchas'] = 1;
  }else{
    // Add the data here when get info
    echo  $_POST['starttime']; 
    addTimes($_SESSION['username'],$_POST['starttime'],$endtime);
   
    for($index =0;$index< 6;$index++){
      $text1 = "hiddenImage$index";
      $text2 = "hiddenText$index";

      $img = $_POST[$text1];
      $text = $_POST[$text2];
      addDistractors($_SESSION['username'],$img,$text);
    }
     addAnswer($_SESSION['username'],$_POST['selected']);
     addMatchingTerm($_SESSION['username'],$_POST['matchterm']);
    $_SESSION['numcaptchas']++;
  }

  
  $counter = $_SESSION['numcaptchas'];
  if($counter < $NUM_CAPTCHAS_PAGES){
    require('captcha.php');
  }else{
    include('evalform.php');
    unset($_SESSION['numcaptchas']);
  }


}catch(Exception $e){
  echo $e;
}

echo $page->getFooter();
?>
